#!/bin/bash

# Checks the output of runtests-sql-all and reports if a regression occurred.
# Only the number of correct tests is counted. This should be improved.
# Currently a diff HTML is also generated when regression is found.

exitcode=0

r() {
 echo "Regression in $1: $2 ($3 needed)"
 ./report-sql -c "$1,p1 $1" -o html/$1-diff.html
 if ((exitcode = 0)); then
  exitcode=$4 # allow non-fatal exit for Botana* since it may be due to external reasons
  fi
 }

MYDIR=`pwd $0`
cd $MYDIR
cat html/all.html | grep \"summary | grep -v Summary | cut -f2 -db | tr '></' '   ' | awk {'printf "%s ", $1'} > tmp/all.summary.out
read e1 e2 b e2g bg e3a ow e3b a ad w wd < tmp/all.summary.out

exitcode=0

n=35;  if ((e1 < $n));   then r "Recio" $e1 $n 1; fi
n=200; if ((e2 < $n));  then r "Botana" $e2 $n 0; fi
n=179; if ((b < $n));   then r "Botana,D" $b $n 0; fi
n=144; if ((e2g < $n)); then r "BotanaGiac" $e2g $n 1; fi
n=181; if ((bg < $n));  then r "BotanaGiac,D" $bg $n 1; fi
n=88; if ((e3a < $n));  then r "OpenGeoProver_Wu" $e3a $n 1; fi
n=89; if ((ow < $n));   then r "OpenGeoProver_Wu,D" $ow $n 1; fi
n=70; if ((e3b < $n));  then r "OpenGeoProver_Area" $e3b $n 1; fi
n=164; if ((a < $n));   then r "Auto" $a $n 1; fi
n=181; if ((ad < $n));  then r "Auto,D" $ad $n 1; fi
n=136; if ((w < $n));   then r "Web" $w $n 1; fi
n=153; if ((wd < $n));  then r "Web,D" $wd $n 1; fi # midpoints-perpendiculars-are-collinear-ex266 works since Christmas 2015, Pappus is unstable

exit $exitcode
